n = 100;
A = zeros(n,n);

A(1,1) = 2; A(n,n) = 2; A(2,1) = -1; A(n-1,n) = -1;
for i = 2:(n-1)
    A(i-1,i) = -1;
    A(i+1,i) = -1;
    A(i,i) = 2;
end

eigens = eig(A);
errors = zeros(1,n);

for iter = 1:100000

    [Q,R] = qr(A);
    A = R * Q;

    for i = 1:n
        errors(i) = abs((eigens(n+1-i) - A(i,i)) / eigens(n+1-i));
    end
    if max(errors) <= 0.0001
        break
    end
    disp(iter)
end
for i = 1:n
    disp(A(i,i))
end
